import React, { PureComponent } from 'react'
import store from '../store'

export class ReduxByAdd extends PureComponent {
  constructor() {
    super()

    this.state = {
      stateCounter: store.getState().counter
    }
  }

  componentDidMount() {
    // 订阅：
    store.subscribe(() => {
      const stateCounter = store.getState()
      this.setState({
        stateCounter
      })
    })
  }
  render() {
    const { stateCounter } = this.state
    return (
      <div>
        <h4>计数器：{stateCounter}</h4>
        <button>点击 +1</button>
        <button>点击 +5</button>
      </div>
    )
  }
}

export default ReduxByAdd
